/*
 * PureMVC - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
 * Your reuse is governed by Creative Commons Attribution 3.0 License
 */

package org.puremvc4gwt.client.patterns.observer;

import org.puremvc4gwt.client.patterns.facade.Facade;

/**
 * A Base <code>INotifier</code> implementation.
 * 
 * <P>
 * <code>MacroCommand, Command, Mediator</code> and <code>Proxy</code> all
 * have a need to send <code>Notifications</code>.
 * <P>
 * <P>
 * The <code>INotifier</code> interface provides a common method called
 * <code>sendNotification</code> that relieves implementation code of the
 * necessity to actually construct <code>Notifications</code>.
 * </P>
 * 
 * <P>
 * The <code>Notifier</code> class, which all of the above mentioned classes
 * extend, provides an initialized reference to the <code>Facade</code>
 * Singleton, which is required for the convienience method for sending
 * <code>Notifications</code>, but also eases implementation as these classes
 * have frequent <code>Facade</code> interactions and usually require access
 * to the facade anyway.
 * </P>
 * 
 * @see org.puremvc4gwt.client.patterns.facade.Facade Facade
 * @see org.puremvc4gwt.client.patterns.mediator.Mediator Mediator
 * @see org.puremvc4gwt.client.patterns.proxy.Proxy Proxy
 * @see org.puremvc4gwt.client.patterns.command.SimpleCommand SimpleCommand
 * @see org.puremvc4gwt.client.patterns.command.MacroCommand MacroCommand
 *
 * todo check : seems to make sense to provide the concrete type of Facade because
 * a {@link org.puremvc4gwt.client.patterns.mediator.Mediator} or
 * {@link com.google.gwt.user.client.Command} need access to typed APIs
 * (to proxy-s, for example).
 */
public class Notifier<F extends Facade>
{

	/**
	 * Local reference to the Facade Singleton
	 */
	protected F facade = (F)Facade.getInstance();   //todo

	/**
	 * Send an <code>INotification</code>s.
	 * 
	 * <P>
	 * Keeps us from having to construct new notification instances in our
	 * implementation code.
	 * 
	 * @param notificationName
	 *            the name of the notiification to send
	 * @param body
	 *            the body of the notification (optional)
	 * @param type
	 *            the type of the notification (optional)
	 */

	public void sendNotification( String notificationName, Object body,
			String type )
	{
		this.facade.sendNotification( notificationName, body, type );
	}


    /**
     * Helpers
     */
    public void notifyObservers(String name, Object body, String type ) {
        this.facade.notifyObservers(new Notification(name, body, type));
    }

    public void notifyObservers(String name, Object body) {
        this.facade.notifyObservers(new Notification(name, body, null));
    }

    public void notifyObservers(String name) {
        this.facade.notifyObservers(new Notification(name, null, null));
    }
}
